package com.chen.product.controller;

import com.chen.model.entity.product.Category;
import com.chen.model.entity.product.ProductSku;
import com.chen.model.vo.common.Result;
import com.chen.model.vo.common.ResultCodeEnum;
import com.chen.model.vo.h5.IndexVo;
import com.chen.product.service.CategoryService;
import com.chen.product.service.ProductSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author cgj
 * @date 4/12/25 2:57 PM
 */
//@CrossOrigin    使用网关处理跨域,这个就不需要了,写了会出错
@RestController
@RequestMapping("/api/product")
public class IndexController {
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private ProductSkuService productSkuService;

    /**
     * 首页数据查询
     * @return
     */
    @GetMapping("/index")
    public Result<IndexVo>  listIndexDate(){
        // 获取一级分类集合
        List<Category> categoryList=categoryService.listFirstLevel();
        // 获取热销商品sku的集合(排序)
        List<ProductSku> productSkuList=productSkuService.listSku();
        //组装数据
        IndexVo indexVo = new IndexVo();
        indexVo.setCategoryList(categoryList);
        indexVo.setProductSkuList(productSkuList);
        return Result.build(indexVo, ResultCodeEnum.SUCCESS);
    }
}
